package com.hospital.controller;

import com.hospital.service.MedicineService;
import com.hospital.vo.MedicineVO;
import com.hospital.vo.ResponseVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

/**
 * 药品的控制器
 *
 * @author gzy
 * @date 2022/03/28
 */
@Slf4j
@RestController
@RequestMapping("/medicine")
public class MedicineController {

    @DubboReference(check = false)
    private MedicineService medicineService;

    /**
     * 获取所有药品信息
     *
     * @return 药品信息列表
     */
    @GetMapping("/getAllMedicine")
    public ResponseVO getAllMedicine(@RequestParam(defaultValue = "1") Integer pageNum,
                                     @RequestParam(defaultValue = "3") Integer pageSize) {
        return medicineService.getAllMedicine(pageNum, pageSize);
    }

    /**
     * 根据药品编号获取药品的详细信息
     *
     * @param medicineId 药品编号
     * @return 药品详细信息
     */
    @GetMapping("/getMedicineDetails")
    public ResponseVO getMedicineDetails(String medicineId) {
        log.debug("药品编号" + medicineId);
        return medicineService.getMedicineDetails(medicineId);
    }

    /**
     * 添加药品信息
     *
     * @param medicineVO 药品的VO
     * @return 药品是否成功添加
     */
    @PostMapping("/addMedicine")
    public ResponseVO addMedicine(MedicineVO medicineVO) {
        log.debug("添加药品：" + medicineVO);
        return medicineService.addMedicine(medicineVO);
    }

    /**
     * 多行删除：根据药品编号删除药品信息
     *
     * @param medicineIds 药品编号列表
     * @return 药品是否成功删除
     */
    @DeleteMapping("/delMedicine")
    public ResponseVO delMedicine(String[] medicineIds) {
        return medicineService.delMedicine(medicineIds);
    }

    /**
     * 根据药品编号修改药品信息
     *
     * @param medicineVO 药品的VO
     * @return 药品信息是否成功修改
     */
    @PutMapping("/updateMedicine")
    public ResponseVO updateMedicine(MedicineVO medicineVO) {
        return medicineService.updateMedicine(medicineVO);
    }

    /**
     * 条件搜索，模糊查询：根据药品名称和类别查询对应的药品集
     *
     * @param medicineName 药品名称
     * @param medicineType 药品类别
     * @return 药品的结果集
     */
    @GetMapping("/searchMedicine")
    public ResponseVO searchMedicine(String medicineName, Integer medicineType) {
        return medicineService.searchMedicine(medicineName, medicineType);
    }
}
